/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import java.util.ArrayList;

/**
 *
 * @author Camilogaos
 */
public class MainController {
    
    private ArrayList<Double> matrizGeneral [][]; 
    private int indicesCeldas[];
    
    public MainController(int nFilas, int mColumnas ){
       
       matrizGeneral = new ArrayList[nFilas][mColumnas];
       indicesCeldas = new int[nFilas*mColumnas];
    }
    
    public int[] getIndicesCeldas() {
        return indicesCeldas;
    }

    public void setIndicesCeldas(int[] indicesCeldas) {
        this.indicesCeldas = indicesCeldas;
    }

    

    public ArrayList<Double>[][] llenarMatrizLambdasKIguales(int valorK, int nFilas, int mColumnas, Double valorL[]) {
        for (int i = 0; i < matrizGeneral.length; i++) {
            for (int j = 0; j < matrizGeneral[0].length; j++) {
                matrizGeneral[i][j] = new ArrayList<Double>();
            }
        }
       for(int i =0;i<matrizGeneral.length;i++){
           for (int j = 0; j < matrizGeneral[0].length; j++) {
               for (int k = 0; k < valorK; k++) {
                   matrizGeneral[i][j].add(calcularDLG(valorL[0],valorL[1],valorL[2],valorL[3]));
               }
           }
       }
       return matrizGeneral;
    }

    public ArrayList<Double>[][] llenarMatriz(Double granMedia, Double[] Betas, Double[] Taos, Integer[][] matrizM, int nFilas, int mColumnas, ArrayList<Double>[][] matrizLambdas){
        //TODO implementar
        for (int i = 0; i < matrizGeneral.length; i++) {
            for (int j = 0; j < matrizGeneral[0].length; j++) {
                matrizGeneral[i][j] = new ArrayList<Double>();
            }
        }
        
       for(int i =0;i<matrizGeneral.length;i++){
           for (int j = 0; j < matrizGeneral[0].length; j++) {
               for (int k = 0; k < matrizM[i][j]; k++) {
                   double lambda1 = matrizLambdas[i][j].get(0);
                   double lambda2 = matrizLambdas[i][j].get(1);
                   double lambda3 = matrizLambdas[i][j].get(2);
                   double lambda4 = matrizLambdas[i][j].get(3);
                   matrizGeneral[i][j].add(granMedia+Betas[i]+Taos[j]+calcularDLG(lambda1,lambda2,lambda3,lambda4));
               }
           }
       }
       return matrizGeneral;        
    }
    
    public static double calcularDLG(double l1, double l2, double l3, double l4){
        double u = Math.random();
        return (l1+Math.pow(u,l3)-Math.pow((1-u),l4))/l2;
    }
}